package com.practice.designMode.coupon;

import com.alibaba.fastjson2.JSONObject;

import java.math.BigDecimal;

public class DiscountStrategy implements CouponRuleStrategy{
    @Override
    public boolean validate(Order order, UserCoupon userCoupon, JSONObject ruleJson) {
        // 校验最低折扣金额
        BigDecimal minDiscount = ruleJson.getBigDecimal("minDiscount");
        BigDecimal discountAmount = order.getAmount()
                .multiply(BigDecimal.ONE.subtract(ruleJson.getBigDecimal("discountRate")));
        return discountAmount.compareTo(minDiscount) >= 0;    }

    @Override
    public CouponType supportCouponType() {
        return CouponType.DISCOUNT;
    }
}
